package com.xxl.job.executor.service.jobhandler;

import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.executor.mybatis.entity.JobUser;
import com.xxl.job.executor.mybatis.service.JobUserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

import static com.xxl.job.executor.service.jobhandler.ShardingBatchInsert.getStringReturnT;

/**
 * @author: 吴多强
 * @description: 调度任务-主任务
 */
@Component
public class ShardingParentJob {
    private static Logger logger = LoggerFactory.getLogger(ShardingParentJob.class);
    @Resource
    private JobUserService jobUserService;

    @XxlJob("ShardingParentJob")
    public ReturnT<String> shardingJobHandler(String param) throws Exception {
        String[] params = StringUtils.delimitedListToStringArray(param, "-");
        // 开始
        int start = Integer.parseInt(params[0]);
        // 结束
        int end = Integer.parseInt(params[1]);
        logger.info("开始" + start + "结束" + end);
        List<JobUser> jobUsers = new ArrayList<>();
        return getStringReturnT(start, end, jobUsers, jobUserService);
    }
}
